class Friend:
    def _init_(self):
        self.friend_li = []
    def welcome(self):
        print(" ** 欢迎使用好友管理系统 ** ")
        print("1:添加好友")
        print("2:删除好友")
        print("3:备注好友")
        print("4:展示好友")
        print("5:好友分组")
        print("6:退出")
        while True:
            option = input("请选择功能\n")
            if option == '1':
                self.add_friend()
            elif option == '2':
                self.del_friend()
            elif option == '3':
                self.modify_friend()
            elif option == '4':
                self.show_friend()
            elif option == '5':
                self.group_friend()
            elif option == '6':
                break
            
    def get_all_friends(self):
        new_li = []
        for friend_li_elem in self.friend_li:
            if type(friend_li_elem) == dict:
                [new_li.append(dict_elem_name) for
                dict_elem in friend_li_elem.values()
                for dict_elem_name in dict_elem]
            else:
                new_li.append(friend_li_elem)
        return new_li
    def get_all_groups(self):
        groups = []
        for frirend_li_elem in self.friend_li:
            if type(friend_li_elem) == dict:
                groups.append(friend_li_elem)
        return groups
    def get_all_groups_name(self):
        groups_name = []
        for dict_elem in self.get_all_groups():
            for j in dict-elem:
                groups_name.append(j)
        return groups_name


    def del_friend(self):
        if len(self.friend_li) !=0:
            del_name =input("请输入删除好友的姓名")
            #删除好友未分组
            if del_name in self.friend_li:
                self.friend_li.remove(del_name)
                print('删除成功')
            else:
                if del_name in self.get_all_friend():
                    for group_date in self.get_all_groups():
                        for group_friend_li in
    group_data.values():
    if del_name in group_friend_li:
     group_friend_li.remove(del_
     continue
          else:
               print('好友列表为空')
    def modify_friend(self):
        friends = self.get_all_friends()
        if len(friend)== 0:
            print('好友列表为空')
        else:
            before_name = input("请输入要修改的好友姓名：")
            after_name = input("请输入修改后的好友姓名：")
            if before-name in self.friend_li:
                friend_index = 
    self.friend_li.index(before_name)
                   self.friend_li[friend_index] = after_name
                   print("备注成功")
                elif before_name not in self.friend_li:
                    for friend_li_elem in self.friend_li:
                        if type(friend_li_elem) == dict:
                            for dict_elem in
    friend_li_elem.values():
                              if before_name in dict_elem:
                                modify_index = 
    dict_elem.index(before_name)
                               dict_elem[modify_index] =
     after_name
                   print('备注成功')
      def group_friend(self):
        create_group = input("是否创建新的分组y/n\n")
        friends = self.get_all_friends()
        if create_group == 'y':
            if len(friends)==0:
                print("当前没有任何好友")
            else:
                # 请创建分组
                group_name = input("请输入分组名称：\n")
                group_name_li = list()
                # 展示当前好友
                print(friends)
                # 移动联系人到哪个组
                friend_name = input("请输入好友名称：\n")
                 if friend_name in friends:
                    all_friend = []
                    for friend_li_elem in self.friend_li:
                        if type(friend_li_elem) == dict:
                            [all_friend.append(dict_friends) for
                             dict_elem in friend_li_elem.values()
                             for dict_friends in dict_elem]
                        else:
                            all_friend.append(friend_li_elem)
                    if friend_name in all_friend:
                        group_name_li.append(friend_name)
                        self.friend_li.remove(friend_name)
                        # 构建字典： {组名称：分组列表}
                        friend_dict = dict()
                        friend_dict[group_name] = group_name_li
                        self.friend_li.append(friend_dict)
                    else:
                        print("请输入正确的名称")
                else:
                    print('请输入正确好友名称')
                     elif create_group =='n':
            # 显示当前的分组，将用户添加到指定的组
            current_groups = self.get_all_groups()
            print('当前分组:')
            for  current_group in current_groups:
                for group_name in current_group:
                    print(group_name)
            add_group = input('请选择添加的组:\n')
            # 判断用户输入的组名是否在当前已存在的分组名中
            if add_group in self.get_all_groups_name():
                # 添加好友到指定的组
                add_name = input('请选择添加的好友名称：\n')
                # 判断用户输入的好友是否存在好友列表中
                if add_name in self.friend_li:
                    # 判断用户是否在其他组中
                    if add_name not in current_groups:
                        # 将好友添加到指定的组内
                        add_group_index = \
                            self.get_all_groups_name().index(add_group)
                        current_groups[add_group_index][
                            add_group].append(add_name)
                else:
                    print('该好友已在其他分组中')
            else:
                print('请输入正确的组名')
    if __name__ == '__main__':
    friend = Friend()
    friend.welcome()